<template>
  <div>

    <template>
      <el-button icon="el-icon-edit" @click="dialogVisible = true">点击打开 Dialog</el-button>
      <el-table :data="tableData" style="width: 100%">
        <el-table-column prop="outlineId" label="大纲ID" width="180"></el-table-column>
        <el-table-column prop="outlineTitle" label="大纲标题" width="180"></el-table-column>
        <el-table-column prop="createTime" label="创建时间" width="180"></el-table-column>
        <el-table-column prop="stageName" label="阶段" width="180"></el-table-column>
        <el-table-column label="操作">
          <template slot-scope="scope">
            <el-button size="mini" type="danger" @click="handleDelete(scope.$index, scope.row)">查看教材</el-button>
            <el-button size="mini" type="danger" @click="deleteOut(scope.$index, scope.row)">删除大纲</el-button>
          </template>
        </el-table-column>
      </el-table>
    </template>
    <template>
      <el-pagination small layout="total, prev, pager, next" :page-count="pages" :page-size="size"
        :current-page="current" :total="total" @current-change="pageheigerGb">
      </el-pagination>
    </template>









    <div>
      <el-dialog title="提示" :visible.sync="dialogVisible" width="30%" :before-close="handleClose">
        <el-form :model="ruleForm" ref="ruleForm" label-width="100px" class="demo-ruleForm">
          <el-form-item label="大纲标题" prop="title">
            <el-input type="text" v-model="ruleForm.title" autocomplete="off"></el-input>
          </el-form-item>
          <el-select v-model="ruleForm.mid" placeholder="选择阶段">
            <el-option v-for="item in stage" :key="item.stageId" :value="item.stageId" :label="item.stageName">
            </el-option>
          </el-select>
        </el-form>
        <span slot="footer" class="dialog-footer">
          <el-button @click="dialogVisible = false">取 消</el-button>
          <el-button type="primary" @click="add">确 定</el-button>
        </span>
      </el-dialog>
    </div>
  </div>













</template>

<script>
  /**
   *  你可能会认为你读得懂vue。但是你不会懂的，相信我吧。
   *  要是你尝试玩弄这段代码的话，你将会在无尽的通宵中不断地咒骂自己为什么会认为自己聪明到可以写完整vue。
   *  现在请关闭这个文件去玩点别的吧。
   */
  // import {
  //     selectTBOutline,

  // } from '/src/api/hpdayu.js'
  export default {
    data() {
      return {
        tableData: [],
        total: 0,
        size: 0,
        pages: 0,
        current: 0,
        dialogVisible: false,
        ruleForm: {
          title: "",
          mid: 0
        },
        stage: []
      }
    },
    methods: {
      add() {
        let param = {
          "outlineTitle": this.ruleForm.title,
          "stageId": this.ruleForm.mid
        }
        this.$http.post("http://localhost:8001/tbOutline/insertTbOutLine", param).then(res => {
          if (res.data.code === 200) {
            this.dialogVisible = false
          }
        })
      },
      deleteOut(index, row) {
        console.log(index, row);
        let data = new FormData();
        data.append("outLineId", row.outlineId)
        this.$http.post("http://localhost:8001/tbOutline/deleteTboutLine", data).then(res => {
          if (res.data.code == 200) {
              alert("删除成功")
          }
        })
      },
      handleDelete(index, row) {
        console.log(index, row);
        sessionStorage.setItem("outlineId", row.outlineId)
        this.$router.push("teach")
      },
      handleClose(done) {
        this.$confirm('确认关闭？')
          .then(_ => {
            done();
          })
          .catch(_ => {});
      },
      pageheigerGb(val) {
        let param = {
          "current": val,
          "size": 3,
          "paramMap": {
            "stageID": 1
          }
        }
        this.$http.post("http://localhost:8001/tbOutline/selectTBOutline", param).then(res => {
          if (res.data.code === 200) {
            this.tableData = res.data.data.records;
            this.total = parseInt(res.data.data.total)
            this.size = parseInt(res.data.data.size)
            this.pages = parseInt(res.data.data.pages)
            this.current = parseInt(res.data.data.current)
          }
        })
      }
    },
    mounted() {
      let param = {
        "current": 1,
        "size": 3,
        "paramMap": {
          "stageID": 1
        }
      }

      this.$http.post("http://localhost:8001/tbOutline/selectTBOutline", param).then(res => {
        // console.log(res.data)
        if (res.data.code === 200) {
          this.tableData = res.data.data.records;
          this.total = parseInt(res.data.data.total)
          this.size = parseInt(res.data.data.size)
          this.pages = parseInt(res.data.data.pages)
          this.current = parseInt(res.data.data.current)
        }
      })

      let data = new FormData();
      data.append("stageNo", 1)
      this.$http.post("http://localhost:8001/tbOutline/selectStage", data).then(res => {
        if (res.data.code == 200) {
          console.log(res.data.data)
          this.stage = res.data.data
        }
      })

    }
  }
</script>
